package com.droidnova.android.games.vortex;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import java.nio.ShortBuffer;

import javax.microedition.khronos.opengles.GL10;

public class axis 
{
	// Our vertex buffer.
	private FloatBuffer _vertexBuffer;

	// Our index buffer.
	private ShortBuffer _indexBuffer;
	
	
	private short[] _indices = {0, 1,0,2,0,3};  // The order we like to connect them.
	
	private float[] _vertices = {
			 0.0f,0.0f,0.0f,           // origin -0
			 10.0f, 0.0f, 0.0f,       // x axis-1
			 0.0f, 10.0f, 0.0f,     //   y axis -2
			 0.0f, 0.0f, 10.0f,        // z axis -3
	     };
	
	public axis() {
		// a float is 4 bytes, therefore we multiply the number if 
		// vertices with 4.
		ByteBuffer vbb = ByteBuffer.allocateDirect(_vertices.length * 4);
		vbb.order(ByteOrder.nativeOrder());
		_vertexBuffer = vbb.asFloatBuffer();
		_vertexBuffer.put(_vertices);
		_vertexBuffer.position(0);
		
		// short is 2 bytes, therefore we multiply the number if 
		// vertices with 2.
		ByteBuffer ibb = ByteBuffer.allocateDirect(_indices.length * 2);
		ibb.order(ByteOrder.nativeOrder());
		_indexBuffer = ibb.asShortBuffer();
		_indexBuffer.put(_indices);
		_indexBuffer.position(0);
	}
	public void draw(GL10 gl) {
		
		gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
		// Specifies the location and data format of an array of vertex
		// coordinates to use when rendering.
		 // set the color of our element
	    //gl.glColor4f(0.5f, 0.5f, 1.0f, 0.5f);	
	    // define the vertices we want to draw
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, _vertexBuffer);
        // finally draw the vertices
        gl.glLineWidth(6);
        gl.glRotatef(45.0f, 1.0f,1.0f,1.0f);
        gl.glDrawElements(GL10.GL_LINES, _indices.length, GL10.GL_UNSIGNED_SHORT, _indexBuffer);	
		// Disable the vertices buffer.
		gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
		
	}
	
}
